using System;
using System.IO;
using System.Diagnostics;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

//using IBM.Data.DB2;
using Novell.Directory.Ldap;
using ldapAccountGen;

namespace ldapAccountGen
{
    /// <summary>
    /// Summary descripton for SAG.
    /// </summary>

    class MainClass
    {
        public static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Pass the start argument: [c d r]");

                string argIn = "";
                if (args.Length > 0)
                {
                    Console.WriteLine("Passed switch: " + args[0]);
                    argIn = args[0];
                }
                else
                {
                    argIn = Console.ReadLine();
                }
                string logFileName = "AccountGen-";
                switch (argIn)
                {
                    case "c":
                        logFileName = "AddModRegAccounts-";
                        break;
                    case "d":
                        logFileName = "DumpintoDb-";
                        break;
                    case "r":
                        logFileName = "RemoveExpired-";
                        break;
                    default:
                        break;
                }
                //
                // Need to setup a logger object that lets you pass the value of type to log
                // and the type of log file to use plus whether or not to write to console.
                //
                string timeStamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
                Logger log = new Logger();
                log.FileName = logFileName + timeStamp + ".log";
                log.ELogFile = "SAG2_error.log";
                log.create();
                SController ctl = new SController();
                if (argIn == "c")
                {
                    ctl.create(log);
                }
                if (argIn == "d")
                {
                    ctl.dump(log);
                }
                if (argIn == "r")
                {
                    ctl.remove(log);
                }
                log.write("============================================================", "APPEND");
                log.write("FINISHED!!!", "APPEND");
            }
            catch (IndexOutOfRangeException e)
            {
                Console.Error.WriteLine("Index Out of Range Exception: " + e.Message);
                Environment.Exit(1);
            }
            catch (FileNotFoundException e)
            {
                Console.Error.WriteLine("File not found Exception: " + e.Message);
                Environment.Exit(1);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Exception: " + e.Message);
                Environment.Exit(1);
            }
            finally
            {
                Console.WriteLine("Done!");
            }
        }        
    }
}
